package conf

import (
	"fmt"
	"github.com/go-ini/ini"
	"log"
)

type App struct {
	*Kafka   `ini:"kafka"`
	*Collect `ini:"collect"`
	*Etcd    `ini:"etcd"`
}

type Kafka struct {
	IP    string `ini:"ip"`
	Port  string `ini:"port"`
	Topic string `ini:"topic"`
}

type Collect struct {
	Filename   string `ini:"log_file_path"`
	BufferSize int    `ini:"buffer_size"`
}

type Etcd struct {
	IP            string `ini:"ip"`
	Port          string `ini:"port"`
	LogCollectKey string `ini:"log_collect_key"`
}

type Pair struct {
	Path       string `json:"path,omitempty"`
	BufferSize int    `json:"buffer_size,omitempty"`
}

func (p *Pair) String() string {
	return fmt.Sprintf("Pair={Path=%s, BufferSize=%d}",
		p.Path, p.BufferSize)
}

var Default *App

func init() {
	cfg := new(App)
	conf, err := ini.Load("conf.ini")
	conf.MapTo(cfg)
	if err != nil {
		// 初始化配置
		log.Fatalln(err)
	}
	Default = cfg
}
